package com.ellfors.module_first.multi_list_type

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.chad.library.adapter4.layoutmanager.QuickGridLayoutManager
import com.ellfors.common.base.BaseActivity
import com.ellfors.common.base.EmptyViewModel
import com.ellfors.common.ext.toast
import com.ellfors.module_first.databinding.ActivityMultiListTypeBinding

/**
 * 测试BaseRecyclerViewAdapterHelper的多样式布局
 * @property mAdapter MultiListTypeAdapter
 */
class MultiListTypeActivity : BaseActivity<ActivityMultiListTypeBinding, EmptyViewModel>() {

    companion object {
        fun start(activity: AppCompatActivity) {
            activity.startActivity(Intent(activity, MultiListTypeActivity::class.java))
        }
    }

    private val mAdapter by lazy {
        MultiListTypeAdapter().apply {
            setOnItemClickListener { adapter, view, position ->
                val data = adapter.getItem(position) as MultiBean
                data.data.toast()
            }
        }
    }

    override fun initView() {
        showTitleBar("测试多样式布局")
        mBinding.rcvTest.apply {
            layoutManager = QuickGridLayoutManager(this@MultiListTypeActivity, 3)
            adapter = mAdapter
        }
    }

    override fun initData() {
        val list = mutableListOf<MultiBean>()
        for (i in 1..10) {
            list.add(MultiBean(1, "First_$i"))
        }
        list.add(MultiBean(3, "Third_1"))
        for (i in 1..10) {
            list.add(MultiBean(2, "Second_$i"))
        }
        mAdapter.submitList(list)
    }
}